home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
basic
/
NewFDConvert.lha
/
NewFDConvert
/
newfdconvert.asc
< prev
next >
Wrap
Text File
|
1999-01-16
|
13KB
|
596 lines
;last modified JAN 15 1999 by Curt Esser
;NEEDS Blitzlibs:amigalibs.res!
;CHANGED - checks for clashing lib numbers
;CHANGED - uses ReqTools for ALL requesters
;CHANGED - scans Userlibs/ and Otherlibs/ directories too
;CHANGED - option to over-write existing library files
; - if overwritten, same lib # is re-used to
; - prevent tokenization problems with old sources
;CHANGED - larger window to see all commands in .fd file
;CHANGED - useless window close gadget removed
;ADDED - doesn't quit until asked to by user
;ADDED - can call "MakeDefLibs" (or other) program
;ADDED - gave window a re-size gadget
;ADDED - doesn't automatically quit if
; - library Exists and user cancels overwrite
; -----------------------------------------------------------------
; fdconvert.bb2 with added file requesters!
; Right, now create Resource fixed
; Now the program presents you the best library ID !!!
; And now the executable don' t suxx if the library isn' t available...
v$="$VER: NewFDConvert v1.1 (12-27-1998) ACID/JLB"
WBStartup
NoCli
WBenchToFront_
FindScreen 0 ;grab the WB screen
MaxLen p$=192
MaxLen f$=192
MaxLen fdpa$=192
MaxLen lib$=192 ;for file requesters
lib$="LIBS:" ;default path to actual libraries
Dim usedlibs.w(255) ;is this lib number in use?
bar$=Chr$(10) ;for the RT requesters
cq$="Continue| Quit "
Dim d$(3) ;the directories to be scanned
d$(1)="BlitzLibs:AmigaLibs/" ;for Blitz libraries
d$(2)="Blitzlibs:OtherLibs/" ;assumes standard setup
d$(3)="Blitzlibs:UserLibs/" ;and "Blitzlibs:" assign!
;-------------- makes a RTrequester-compatable string ----------
; of the free library numbers
Function.s MakeFreeList{}
SHARED usedlibs(),bar$
Format "000"
For i = 1 To 255
If usedlibs(i)=0 ;ah, a free library number!
ret$=ret$+Str$(i)+" "
curlen.w+4
If curlen>60
ret$+bar$
curlen=0
EndIf
EndIf
Next
Format ""
Function Return ret$
End Function
;--------------------------------------------------------------
Statement align{}
;
SHARED co$
;
l.q=Len(co$)
If l/2<>Int(l/2) Then co$+Chr$(0)
;
End Statement
;--------------------------------------------------------------
Statement fillin{src.l} ;src=source to change
;
SHARED co$
;
co$=Left$(co$,src)+Mkl$(Len(co$))+Mid$(co$,src+5)
;
End Statement
;---------------------------------------------------------------
Statement dir{} ;scans directories for free library
SHARED usedlibs(),d$() ;numbers
libnr.w=0
For d.b=1 To 3
dev$=d$(d)
;dev$="Blitzlibs:Amigalibs/"
lock.l=Lock_(&dev$,-2)
If lock
WColour 2,0
NPrint " Checking ",dev$
WPrintScroll
WColour 1,0
infoadr.l=AllocMem_(260,0)
If infoadr
ok=Examine_(lock,infoadr)
Repeat
ok=ExNext_(lock,infoadr)
If ok AND Peek.l(infoadr+4)=-3 AND Instr(UCase$(Peek$(infoadr+8)),".INFO")=0
rfile$=dev$+Peek$(infoadr+8)
fh.l=Open_(&rfile$,1005)
If fh
Seek_ fh,36,#OFFSET_CURRENT ;36 & 86
Read_ fh,&libnr,2
usedlibs(libnr)=1
Close_ fh
EndIf
EndIf
Until ok=0
FreeMem_ infoadr,260
EndIf
UnLock_(lock)
Else
BeepScreen 0
WColour 3,0
NPrint " Can't locate ",dev$
WPrintScroll
WColour 1,0
EndIf
Next d
NPrint" "
WPrintScroll
End Statement
;---------------------------------------------------------------
Function$ ReadTtype{TT$} ;read the tooltype if found
If FindToolType(TT$)
tl$=FindToolValue(TT$)
Else
tl$="0"
EndIf
Function Return tl$
End Function
;================================================================
; ------------- Set up ----------------
*SC.Screen=Peek.l(Addr Screen(0)) ; get a pointer to screen
*SCFONT.TextAttr=*SC.Screen\Font ; and to the screen's font
HEIGHT_WBFONT.b=(*SCFONT.TextAttr\ta_YSize) ; get font height
fname$=Peek$(*SCFONT.TextAttr\ta_Name); and font name
LoadFont 0,fname$,HEIGHT_WBFONT ; load font name,font height
ww.w=520 ; width of window
wh.w=160 ; height of window
wx.w=ScreenWidth/2-ww/2 ; centre...
;wy.w=ScreenHeight/2-wh/2 ; ...window
wy=HEIGHT_WBFONT+5 ;put it just below WB title bar
If Window (0,wx,wy,ww,wh,$400|$1|$4|$20," NewFDConvert",1,0)=0
dummy.b=RTEZRequest ("NewFDConvert","Failed to open window!","END")
End ; quit if window can't open
EndIf
;----------- Read the icon for the command button info ----------
If GetIconObject("NewFdConvert")
cmd$=ReadTtype{"COMMAND"} ;the command
pth$=ReadTtype{"PATH"} ;path to the command
param$=ReadTtype{"PARAM"} ;optional parameters
EndIf
If cmd$="0"
btn$=cq$
Else
If pth$<>"0" Then exe$=pth$
exe$+cmd$
If param$<>"0" Then exe$+" "+param$
btn$="Continue|"+cmd$+"| Quit "
EndIf
dp$=ReadTtype{"FD_PATH"} ;set default path to fd files
If dp$<>"0"
fdpa$=dp$
Else
fdpa$="RAM:"
EndIf
;-----------------------------------------------------------------
CatchDosErrs
NPrint " ** NewFDConvert **"
WPrintScroll
NPrint " "
WPrintScroll
NPrint " v1.0 by James L Boyd"
WPrintScroll
NPrint " v1.1 mods by Curt Esser"
WPrintScroll
NPrint " - based on:"
WPrintScroll
NPrint " FDConv by Mark Sibly"
WPrintScroll
NPrint " FDConv v2.0 by Andre Bergmann"
WPrintScroll
NPrint " "
WPrintScroll
DEFTYPE.l
;
;fdinfo prog... suss out an fd file, and return library offsets!
;
; --------- MAIN LOOP ----------------------------------
Repeat
f$=""
fd$=ASLFileRequest$("Select .fd file",fdpa$,f$,"#?.fd")
If fd$="" OR f$="" Then End
f$=""
dest$="blitzlibs:amigalibs/"
Activate 0
Dim n$(1000),h$(1000),p$(1000),o.w(1000)
Dim l$(10),ln(10) ;max libs split-up
If ReadFile(0,fd$)
NPrint " Examining FD File..."
WPrintScroll
FileInput 0:Gosub sussfd:CloseFile 0:Use Window 0
;
;ok... fd file sussed - now to make output file...
;
Gosub makelib
If userabort.b=0
rq$=li$+" saved!"+bar$+"Don't forget to remake your DefLibs"
answer.b=RTEZRequest (" Library done!",rq$,btn$)
Else
rq$="Library conversion aborted"
userabort=0
answer=RTEZRequest (" NewFdConvert",rq$,cq$)
EndIf
If answer=2 ;run "button" command
Execute_ exe$,0,0
answer=RTEZRequest (" NewFdConvert","-- Ready --",cq$)
EndIf
Else
answer=RTEZRequest("ERROR","Couldn't read .fd file",cq$)
EndIf
If answer<>0
Use Window 0
For i = 1 To 10
NPrint " "
WPrintScroll
Next
WColour 2,0
NPrint " ------- READY --------"
For i = 1 To 3
NPrint " "
WPrintScroll
Next
WColour 1,0
EndIf
Until answer=0 ;quit selected on one of the requesters
End
;-----------------------------------------------------------------
.makelib ;n=number of commands...
here0
ll.l=OldOpenLibrary_(&li$)
If ll
CloseLibrary_ ll:islib=-1
Else
ll.l=OpenResource_(&li$)
If ll
islib=0
Else
li$=ASLFileRequest$("Library name",lib$,f$,"#?.library")
li$=f$
If li$=""
userabort=1
Return
EndIf
Goto here0
EndIf
EndIf
;
;li$=library name! - generate amigalibs name
;
nl=(n-1)/127+1 ;how many libs to make
Print " Library will require ",nl
Print" Amigalibs file"
If nl>1 Then Print"s"
NPrint"..."
WPrintScroll
NPrint" "
WPrintScroll
For k=1 To nl ;this bit determines the library numbers...
fh.l=Open_(dest$+li$+Str$(k),#MODE_OLDFILE)
If fh
Seek_ fh,36,#OFFSET_CURRENT ;36 & 86
Read_ fh,&libnr.w,2
Close_ fh
If k=1 ;only do this if first one of >1 part library!
rq$="WARNING - Library already exists!"+bar$
rq$=rq$+dest$+li$+" id#:"+Str$(libnr)
answer.b=RTEZRequest ("NewFDConvert",rq$,"OverWrite|Cancel")
If answer=0
;End
Pop For
userabort.b=1
Return
EndIf
EndIf
DeleteFile_(dest$+li$+Str$(k))
didhave.w=libnr
usedlibs(didhave)=0
WColour 3,0
NPrint " Existing ",li$+Str$(k)," deleted!"
WPrintScroll
NPrint " "
WPrintScroll
WColour 1,0
EndIf
If didhave ;if an overwrite, always use same lib #(s)
ln(k)=didhave
didhave=0
Else
dir{} ;check numbers of existing libraries
For i = 255 To 1 Step -1
If usedlibs(i)=0
bestlibnr=i
i=1
EndIf
Next
error$=""
here
r$=error$+"Available Library numbers:"+bar$+ MakeFreeList{}
r$+bar$+"Enter new library number:"
ln(k)=RTEZGetLongRange("NewFDConvert",r$,1,bestlibnr,bestlibnr)
If ln(k)=0
End
EndIf
If ln(k)>255 OR ln(k)<1
error$="ERROR: Out of range!"+bar$
Goto here
EndIf
If usedlibs(ln(k))=1
error$="ERROR: Library number "+Str$(ln(k))+" already used!"+bar$
Goto here
EndIf
EndIf
Next
ln=ln(1)
;
li2$=li$
clearup:k=Instr(li2$,":"):If k Then li2$=Mid$(li2$,k+1):Goto clearup
clearup2:k=Instr(li2$,"/"):If k Then li2$=Mid$(li2$,k+1):Goto clearup
;
nn=127:li=0
;
For tk=1 To n
;
nn+1
If nn=128
;
If li Then Gosub libdone
;
li+1
If WriteFile(0,dest$+li2$+Str$(li))=0
dummy=RTEZRequest("Error creating File",li$+Str$(li),"DAMN!")
Pop For
Return
EndIf
;
co$=Mkl$(0)+Mki$(ln(li))+String$(Chr$(0),20)
If li=1 Then co$+Mki$(1) Else co$+Mki$(0)
co$+String$(Chr$(0),20)
nn=1
WColour 2,0
NPrint "-------------------------------"
WPrintScroll
WColour 3,0
NPrint " Creating ",li$
WPrintScroll
NPrint" "
WPrintScroll
WColour 1,0
;
EndIf
;
NPrint " CREATING : ",n$(tk),"_",suf$," ",h$(tk)," ",p$(tk)
WPrintScroll
co$+Mki$(6)+Mkl$(0)+Mki$(ln(1))+Mki$(o(tk)) ;type and link
;
p$=Mid$(p$(tk),2)
While Left$(p$,1)="a" OR Left$(p$,1)="d"
If Left$(p$,1)="a"
co$+Chr$(Val(Mid$(p$,2,1))+16)
Else
co$+Chr$(Val(Mid$(p$,2,1)))
EndIf
p$=Mid$(p$,4)
Wend
;
co$+Chr$(-1)
align{}
co$+Mkl$(0)+Mki$(0)+n$(tk)+"_"+suf$+Chr$(0)+h$(tk)+Chr$(0)
align{}
;
Next
;
If co$ Then Gosub libdone
;
Return
.libdone
;
If li=1 ;first one - create 'openlibrary' stuff!
;
;make 'init' nullsub!
;
fillin{$16}
co$+String$(Chr$(0),12):iat=Len(co$)
co$+Mkl$(0)+Mkl$(0)
;
;make 'finit' nullsub!
;
fillin{$1c}
co$+String$(Chr$(0),6)+Mki$(ln(1))+Mki$($1100)+Mki$(0)
co$+Mkl$(0):fat=Len(co$)
co$+Mkl$(0)+Mkl$(0)
;
co$+Mki$(-1)+Mkl$(0)
;
;make 'libinit' code!
;
fillin{iat}
co$+Mkl$($2c780004) ; move.l 4.w,a6
If islib
co$+Mkl$($43fa0022) ;loop lea libname(pc),a1
Else
co$+Mkl$($43fa001d)
EndIf
co$+Mki$($7000) ; moveq #0,d0
co$+Mki$($4eae)
If islib
co$+Mki$(-552) ; jsr openlibrary(a6)
Else
co$+Mki$(-498) ; jsr openresource(a6)
EndIf
; co$+Mki$($4a80) ; tst.l d0
; co$+Mkl$($6700fff4) ; beq loop
co$+Mki$($4e75) ; rts
;
;make 'libfinit' code!
;
fillin{fat}
If islib
; co$+Mkl$($2c780004) ; move.l 4.w,a6
; co$+Mkl$($4eeefe62) ; jmp -$19e(a6)
; Well, the fellowing code should create something like this:
; MOVE.l a1,d0
; TST.l d0
; BEQ skip
; MOVEA.l 4,a6
; JSR -$19e(a6)
; skip:
; RTS
co$+Mkl$($20094A80)
co$+Mkl$($6700000C)
co$+Mkl$($2C790000)
co$+Mkl$($00044EAE)
co$+Mkl$($FE624E75)
co$+Mkl$($70004E75)
Else
co$+Mki$($4e75)
EndIf
;
;add 'name.library'
;
co$+li$+Chr$(0)
;
;All Code Done! - now for reloc stuff
;
re$=Mkl$($3ec)+Mkl$(4)+Mkl$(0)+Mkl$($16)+Mkl$($1c)
re$+Mkl$(iat)+Mkl$(fat)+Mkl$(0)
;
Else
;
co$+Mki$(-1)+Mkl$(0)
;
EndIf
;
While (Len(co$) AND 3)
co$+Chr$(0)
Wend
;
;Now for header stuff
;
cl=Len(co$)/4
;
in$=Mkl$($3f3)+Mkl$(0)+Mkl$(1)+Mkl$(0)+Mkl$(0)
in$+Mkl$(cl)+Mkl$($3e9)+Mkl$(cl)
;
FileOutput 0
Print in$,co$,re$,Mkl$($3f2)
CloseFile 0:DefaultOutput
;
co$="":re$="":Return
.sussfd
n=0:bi=-30:li$="":gen=-1
While NOT Eof(0)
l$=Edit$(256)
If Left$(l$,1)<>"*"
If Left$(l$,2)="##"
c$=LCase$(Mid$(l$,3)):c$=StripLead$(c$,32)
If Left$(c$,6)="public" Then gen=-1
If Left$(c$,7)="private" Then gen=0
If Left$(c$,3)="end" Then Return
If Left$(c$,4)="bias" Then bi=-Val(Mid$(c$,5))
Else
If gen
b1=Instr(l$,"(") ;first bracket
b2=Instr(l$,"(",b1+1) ;second bracket
If b1>0 AND b2>0
n+1
o(n)=bi
n$(n)=Left$(l$,b1-1)
h$(n)=Mid$(l$,b1,b2-b1):If h$(n)="()" Then h$(n)=""
p$(n)=LCase$(Mid$(l$,b2))
Else
NPrint "Error in file :"
WPrintScroll
NPrint l$
WPrintScroll
EndIf
EndIf
bi-6
;
EndIf
Else
n$=Mid$(l$,2):n$=StripLead$(n$,32)
If Left$(n$,1)=Chr$(34)
n2=Instr(n$,Chr$(34),2)-2
If n2>0
li$=Mid$(n$,2,n2)
EndIf
EndIf
EndIf
Wend
Return